<template>
  <div>
    <el-form :inline="true" :model="search" class="demo-form-inline">
      
       <el-row class="table-head-box">
       
        <el-col :span="24" class="flex flex-end input-box">
          <el-form-item label="姓名:" prop="userName">
         <el-input v-model="search.lkParam.user_name" placeholder="姓名"></el-input>
      </el-form-item>
       <el-form-item label="手机号:" prop="mobile">
         <el-input v-model="search.eqParam.mobile" placeholder="手机号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchUserHandler">查询</el-button>
      </el-form-item>
        </el-col>
      </el-row>
      
    </el-form>
    <el-table :data="userList" border style="width: 100%" tooltip-effect="dark" size="mini">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column  prop="mobile" label="电话">
      </el-table-column>
      <el-table-column  prop="userName" label="账号">
      </el-table-column>
      <el-table-column prop="have" label="是否有宠物">
        <template slot-scope="scope">
          <!-- <el-switch
          v-model="scope.row.have"
          active-color="#13ce66"
          inactive-color="#ff4949"
          disabled>
        </el-switch> -->
        <span>{{ scope.row.have ? '有' : '无' }}</span>

        </template>
      </el-table-column>
      <el-table-column prop="plan" label="是否有计划养">
        <template slot-scope="scope">
          <!-- <el-switch
          v-model="scope.row.plan"
          active-color="#13ce66"
          inactive-color="#ff4949"
          disabled>
        </el-switch> -->
        <span>{{ scope.row.plan ? '有' : '无' }}</span>

        </template>
      </el-table-column>
      <el-table-column prop="sign" label="签名">
      </el-table-column>
       <el-table-column prop="portrait" label="头像">
         <template slot-scope="scope">
            <span><img :src="scope.row.portrait+'?imageView2/1/w/80/h/80'"></span>
          </template>
      </el-table-column>
       <el-table-column prop="regtime" label="注册时间">
      </el-table-column>‘
       <el-table-column prop="lastlogintime" label="最近一次登录时间">
      </el-table-column>
      <!-- <el-table-column prop="have" label="登陆限制">
        <template slot-scope="scope">
          <el-switch
          v-model="scope.row.have"
          active-color="#13ce66"
          inactive-color="#ff4949"
          @change="updateUserHandler(scope.row)"
          >
        </el-switch>
        </template>
      </el-table-column> -->
      <el-table-column prop="have"  fixed="right" label="操作" width="260">
        <template slot-scope="scope">
          <el-button class="el-icon-plus" type="primary" size="mini" @change="updateUserHandler(scope.row)">{{ scope.row.have ? '解除黑名单' : '加入黑名单' }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row>
        <el-col :span="24" style="text-align:right;">
            <el-pagination background layout="total,prev, pager, next" :page-count="search.size" :total="search.total" @current-change="sizeChangeHandler"> </el-pagination>
        </el-col>
    </el-row>
  </div>
</template>
<script>
import {userPageListUrl,userSaveUrl} from '@/utils/common'

export default {
  components: {
  },
  data() {
    return {
      userList: [],
      user: null,
      showUserDialog: false,
      authorizationDialog: false,
      userId: null,
      search: {
        current:1,
        size:10,
        total: 0,
        lkParam: {userName:""},
        eqParam:{},
      }
    };
  },
  mounted() {
    this.loadUsers();
  },
  methods: {
    addUserHandler: function () {
      this.user = {status:1};
      this.showUserDialog = true;
    },
    updateUserHandler: function (row) { //更新会员限制状态
    let _this = this;
      row.status = 2;
      
      // let operateText =
      //   publishStatus == 3 ? "通过" : publishStatus == 2 ? "不通过" : "禁播";
      // 执行操作前询问
      _this.$model(`确认限制登陆吗, 是否继续?`, "确定", true, "", "提示")
        .then((resp) => {
         _this.axios.post(userSaveUrl, row).then((res) => {
            if (res.data.status == "SUCCESS") {
              _this.loadUsers();
              _this.$message({
                showClose: true,
                message: "处理成功",
              });
            }
          }).catch((err) => {
           _this.$message({
                type: "warn",
                message: "操作失败",
              });
        })
          
        })
        .catch((err) => {
           _this.$message({
                type: "info",
                message: "操作失败",
              });
        })
    
    },
    loadUsers() {
      this.axios
        .post(userPageListUrl, this.search)
        .then(response => {
          var data = response.data.data;
          this.userList = data.records;
          this.search.total = data.total
        })
        .catch(response => {
          console.log("response -   " + response);
        });
    },
    sizeChangeHandler: function (value) {
      this.search.current = value;
      this.loadUsers();
    },
    searchUserHandler: function () {
      this.search.current=1
      this.loadUsers();
    }
  }
};
</script>
<style scoped>
.grid-content {
  text-align: left;
  height: 45px;
}
</style>
